/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package pkl53.controller;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;
import pkl53.component.IntegerConverter;
import pkl53.component.dateConverter;
import pkl53.model.B1Keterangantempat;
import pkl53.model.B4Art;
import pkl53.model.B4Keteranganumumtenagakerja;
import pkl53.model.B4KeteranganumumtenagakerjaPK;

import pkl53.model.B5Keteranganumumtenagakerjainformal;
import pkl53.model.B6Keteranganumumpekerjaaninformalutama;
import pkl53.model.B7KepalaArt;
import pkl53.model.B8Keteranganperumahandanaset;
import pkl53.model.Kecamatan;
import pkl53.model.Mahasiswa;
import pkl53.model.NoBs;
import pkl53.model.OpsiB1r4;
import pkl53.model.OpsiB5r11;
import pkl53.model.OpsiB5r13;
import pkl53.model.OpsiB5r5;
import pkl53.model.OpsiB5r9;
import pkl53.model.OpsiB6r12a;
import pkl53.model.OpsiB6r16;
import pkl53.model.OpsiB6r17;
import pkl53.model.OpsiB6r18;
import pkl53.model.OpsiB6r22a;
import pkl53.model.OpsiB6r3;
import pkl53.model.OpsiB6r6utamaLain;
import pkl53.model.OpsiB7r3;
import pkl53.model.OpsiB7r4;
import pkl53.model.OpsiB8r1;
import pkl53.model.OpsiB8r2;
import pkl53.model.OpsiB8r3;
import pkl53.model.OpsiB8r5a;
import pkl53.model.OpsiB8r5b;
import pkl53.model.OpsiB8r6;
import pkl53.model.OpsiB8r7a;
import pkl53.model.OpsiB8r7b;
import pkl53.model.OpsiB8r8;
import pkl53.model.OpsiB8r9;
import pkl53.view.Blok123;
import pkl53.view.Blok4;
import pkl53.view.Blok4B;
import pkl53.view.Blok56;
import pkl53.view.Blok56B;
import pkl53.view.Blok789;

/**
 *
 * @author HP G42 (RILLA)
 */
public class SubmitControllerPekerjaan {
    
    
    private B5Keteranganumumtenagakerjainformal modelBlok5 = new B5Keteranganumumtenagakerjainformal();
    private B7KepalaArt modelBlok7 = new B7KepalaArt();
    private B8Keteranganperumahandanaset modelBlok8 = new B8Keteranganperumahandanaset();
    private B6Keteranganumumpekerjaaninformalutama modelBlok6 = new B6Keteranganumumpekerjaaninformalutama();
    private B1Keterangantempat modelBlok1 = new B1Keterangantempat();
    private B4Keteranganumumtenagakerja modelBlok4 = new B4Keteranganumumtenagakerja();
    private Blok123 blok1;
    private Blok4 blok4;
    private Blok4B blok4B;
    private Blok56 blok56;
    private Blok56B blok56B;
    private Blok789 blok789;
    
    
    private String kks;
    private String KksArtNup;
    
    
    
    private ArrayList<B5Keteranganumumtenagakerjainformal> b5List = new ArrayList<B5Keteranganumumtenagakerjainformal>();
    private ArrayList<B6Keteranganumumpekerjaaninformalutama> b6List = new ArrayList<B6Keteranganumumpekerjaaninformalutama>();
    private ArrayList<B7KepalaArt> b7List = new ArrayList<B7KepalaArt>();
    private List <B1Keterangantempat> b1List = new ArrayList<B1Keterangantempat>();
    private List <B4Keteranganumumtenagakerja> b4ModelList = new ArrayList<B4Keteranganumumtenagakerja>();
    IntegerConverter Int = new IntegerConverter();
    dateConverter dateConverter = new dateConverter();
    
    
    
    
    public void insertAllBlok(){
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("pkl53");
        EntityManager em = emf.createEntityManager(); 
        em.getTransaction().begin();
        
        B1Keterangantempat b1 = getModelB1();
        em.persist(b1);
//       
        b4ModelList = getModelB4TenagaKerja();
        for (B4Keteranganumumtenagakerja b4 : b4ModelList) {
                
                em.persist(b4); 
                  }
        
        
//         for (B5Keteranganumumtenagakerjainformal b5 : b5List) {
//                em.persist(b5);
//                  }
//         for (B6Keteranganumumpekerjaaninformalutama b6 : b6List) {
//                em.persist(b6);
//                  }
//         for (B7KepalaArt b7 : b7List) {
//                em.persist(b7);
//                  }
//        B8Keteranganperumahandanaset b8 = getModelB8();
//        em.persist(b8);
        
        em.getTransaction().commit();
        em.close();
        
    
    
    
    }
    
    public List <Kecamatan> getKecamatan(String kodeKecamatan){
        List <Kecamatan> kecamatanList = new ArrayList<Kecamatan>();
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("pkl53PU");
        EntityManager em = emf.createEntityManager(); 
        em.getTransaction().begin();
        Query s = em.createQuery("SELECT k FROM Kecamatan k WHERE k.kecamatanPK.b1r2 = :b1r2").setParameter("b1r2", kodeKecamatan);
        kecamatanList = s.getResultList();
        
        return kecamatanList;
        
        
//        List <B1Keterangantempat> b1List = new ArrayList<B1Keterangantempat>();
//        EntityManagerFactory emf = Persistence.createEntityManagerFactory("pkl53PU");
//        EntityManager em = emf.createEntityManager();
//        B1Keterangantempat b1 = new B1Keterangantempat();
//        Query s = em.createNamedQuery("B1Keterangantempat.findAll");
//        List <B1Keterangantempat> b1List = new ArrayList<B1Keterangantempat>();
//        b1List = s.getResultList();
//        em.close();
//        for(B1Keterangantempat b2 : b1List){
//            System.out.println(b2.getKks());
//        }
//        
        
       
        
        
    
    }
    
    
    public void print(){
        System.out.println(blok1.getB1R1().getText());}

    
    public String getKKS(){
         return getBlok1().getB1R1().getText()+
                          getBlok1().getB1R2().getText()+
                          getBlok1().getB1R3().getText()+
                          getBlok1().getB1R4().getText()+
                          getBlok1().getB1R5a().getText()+
                          getBlok1().getB1R5b().getText()+
                          getBlok1().getB1R6().getText()+
                          getBlok1().getB1R7().getText()+
                          getBlok1().getB1R8().getText();
    }
    public String getKksArtNup(){
        return getKKS()+getBlok56().getB5R1Art().getText()+ getBlok56().getB5R4().getText();
    
    }
    
    public String getKksArt(){
        return getKKS()+getBlok56().getB5R1Art().getText()+ getBlok56().getB5R4().getText();
    
    }
    
    
      public B1Keterangantempat getModelB1(){
        modelBlok1.setKks(getKKS());
        modelBlok1.setB1r1(getBlok1().getB1R1().getText());
        modelBlok1.setB1r2(getBlok1().getB1R2().getText());
        modelBlok1.setB1r3(getBlok1().getB1R3().getText());
        modelBlok1.setB1r4(new OpsiB1r4(getBlok1().getB1R4().getText()));
        modelBlok1.setB1r5a(new NoBs(getBlok1().getB1R1().getText(), getBlok1().getB1R2().getText(), getBlok1().getB1R3().getText(), getBlok1().getB1R5a().getText()));
        modelBlok1.setB1r5b(getBlok1().getB1R5b().getText());
        modelBlok1.setB1r6(getBlok1().getB1R6().getText());
        modelBlok1.setB1r7(getBlok1().getB1R7().getText());
        modelBlok1.setB1r8(getBlok1().getB1R8().getText());
        modelBlok1.setNimPencacah(new Mahasiswa(getBlok1().getB3C1R2().getText()));
        modelBlok1.setTanggalPemeriksaanKP(dateConverter.convertForward(getBlok1().getB3C1R3a().getText()));
        modelBlok1.setTanggalPencacahan(dateConverter.convertForward(getBlok1().getB3C1R3b().getText()));
        return modelBlok1;
    
    }
      
       public List <B4Keteranganumumtenagakerja> getModelB4TenagaKerja(){
           
             List <B4Keteranganumumtenagakerja> b4list = new ArrayList<B4Keteranganumumtenagakerja>();
             for (B4Keteranganumumtenagakerja b4 : getBlok4().getB4Keteranganumumlist()) {
                modelBlok4.setB4Art(b4.getB4Art());
                modelBlok4.setB4KeteranganumumtenagakerjaPK(b4.getB4KeteranganumumtenagakerjaPK());
                modelBlok4.setB4r4(b4.getB4r4());
                modelBlok4.setB4r5(b4.getB4r5());
                modelBlok4.setB4r6(b4.getB4r6());
                modelBlok4.setB4r7(b4.getB4r7());
                modelBlok4.setB4r8(b4.getB4r8());
                modelBlok4.setB4r9(b4.getB4r9());
                modelBlok4.setB4r10(b4.getB4r10());
                modelBlok4.setB4r11(b4.getB4r11());
                modelBlok4.setB4r12(b4.getB4r12());
                modelBlok4.setB4r13(b4.getB4r13());
                modelBlok4.setB4r14(b4.getB4r14());
                modelBlok4.setB4r15(b4.getB4r15());  
                
                 for (B4Keteranganumumtenagakerja b4B : getBlok4B().getB4Keteranganumumlist()){
                 if(b4.getB4r4().equals(b4B.getB4r4())){
                 modelBlok4.setB4r16(b4.getB4r16());
                 modelBlok4.setB4r17(b4.getB4r17());
                 modelBlok4.setB4r18(b4.getB4r18());
                 modelBlok4.setB4r19(b4.getB4r19());
                 modelBlok4.setB4r20(b4.getB4r20());
                 modelBlok4.setB4r21(b4.getB4r21());
                 modelBlok4.setB4r22(b4.getB4r22());
                 modelBlok4.setB4r23(b4.getB4r23());
                 }
               b4list.add(modelBlok4);
             }
             
             }
             return b4list;
       }
      public B5Keteranganumumtenagakerjainformal getModelB5(){
       
        modelBlok5.setKKSArtNup(getKksArtNup());
        modelBlok5.setB5r1a(blok56.getB5R1Nama().getText());
        modelBlok5.setB5r1b(Int.convertForward(getBlok56().getB5R1Art().getText()));
        modelBlok5.setB5r2(getBlok56().getB5R2().getText());
        modelBlok5.setB5r3(getBlok56().getB5R3().getText());
        modelBlok5.setB5r5(new OpsiB5r5(getBlok56().getB5R5().getText()));
        modelBlok5.setB5r6a(getBlok56().getB5R6Prop().getText());
        modelBlok5.setB5r6b(getBlok56().getB5R6Prop().getText());
        modelBlok5.setB5r7a(getBlok56().getB5R7Prop().getText());
        modelBlok5.setB5r7b(getBlok56().getB5R7Kab().getText());
        modelBlok5.setB5r8(getBlok56().getB5R8().getText());
        modelBlok5.setB5r9(new OpsiB5r9(blok56.getB5R9().getText()));
        modelBlok5.setB5r10(getBlok56().getB5R10().getText());
        modelBlok5.setB5r11(new OpsiB5r11(getBlok56().getB5R11().getText()));
        modelBlok5.setB5r12(getBlok56().getB5R12().getText());
        modelBlok5.setB5r13(new OpsiB5r13(getBlok56().getB5R13().getText()));
        modelBlok5.setB5r14a(getBlok56().getB5R14a().getText());
        modelBlok5.setB5r14b(getBlok56().getB5R14b().getText());
        modelBlok5.setB5r15((getBlok56().getB5R15().getText()));
        modelBlok5.setB5r16(getBlok56().getB5R16().getText());
        modelBlok5.setB5r17a(getBlok56().getB5R17().getText());
        modelBlok5.setB5r17b(getBlok56().getB5R17().getText());
        
        return modelBlok5;
  
    }

    
    
    public B6Keteranganumumpekerjaaninformalutama  getModelB6(){
        
       
        modelBlok6.setKKSArtNup(getKksArtNup());
        modelBlok6.setB6r1(getBlok56().getB6R1().getText());
        modelBlok6.setB6r2(getBlok56().getB6R2().getText());
        modelBlok6.setB6r3(new OpsiB6r3(getBlok56().getB6R3().getText()));
        modelBlok6.setB6R3tetapLainnya(getBlok56().getB6R3().getText());
        modelBlok6.setB6R3tidakTetapLainnya(getBlok56().getB6R3().getText());
        modelBlok6.setB6r4a(Int.convertForward(getBlok56().getB6R4a().getText()));
        modelBlok6.setB6r4b(Int.convertForward(getBlok56().getB6R4b().getText()));
        modelBlok6.setB6r5a(Int.convertForward(getBlok56().getB6R5a().getText()));
        modelBlok6.setB6r5b(Int.convertForward(getBlok56().getB6R5b().getText()));
        
        modelBlok6.setB6R6utama(getBlok56().getB6R6().getText());
        modelBlok6.setB6R6utamalainnya(getBlok56().getB6R6().getText());
        modelBlok6.setB6R6lain(getBlok56().getB6R6().getText());
        modelBlok6.setB6R6lainlainnya(getBlok56().getB6R6().getText());
        
        modelBlok6.setB6r7a(Int.convertForward(getBlok56().getB6R7a().getText()));
        modelBlok6.setB6r7b(Int.convertForward(getBlok56().getB6R7b().getText()));
        modelBlok6.setB6r8a(Int.convertForward(getBlok56().getB6R8a().getText()));
        modelBlok6.setB6r8b(Int.convertForward(getBlok56().getB6R8b1().getText()));
        modelBlok6.setB6r9a(getBlok56().getB6R9a().getText());
        modelBlok6.setB6r9b(getBlok56().getB6R9b().getText());
        modelBlok6.setB6r10(getBlok56().getB6R10().getText());
        modelBlok6.setB6r11(getBlok56B().getB6R11().getText());
        modelBlok6.setB6r12a(new OpsiB6r12a(getBlok56B().getB6R12a().getText()));
        modelBlok6.setB6r12b(getBlok56B().getB6R12b().getText());
        modelBlok6.setB6r13((getBlok56B().getB6R13().getText()));
        modelBlok6.setB6r14(getBlok56B().getB6R14().getText());
        
        modelBlok6.setB6r15a(Int.convertForward(getBlok56B().getB6R15uang().getText()));
        modelBlok6.setB6r15b(Int.convertForward(getBlok56B().getB6R15uang().getText()));
        
        modelBlok6.setB6r16(new OpsiB6r16(getBlok56B().getB6R16().getText()));
        modelBlok6.setB6r17(new OpsiB6r17(getBlok56B().getB6R17().getText()));
        modelBlok6.setB6R17lainnya(getBlok56B().getB6R17().getText());
        
        modelBlok6.setB6r18(new OpsiB6r18(getBlok56B().getB6R18().getText()));
       
        modelBlok6.setB6r19((getBlok56B().getB6R19().getText()));
        modelBlok6.setB6r20a(Int.convertForward(getBlok56B().getB6R20uang().getText()));
        modelBlok6.setB6r20b(Int.convertForward(getBlok56B().getB6R20uang().getText()));
        modelBlok6.setB6r21a((getBlok56B().getB6R21a().getText()));
        modelBlok6.setB6r21b((getBlok56B().getB6R21b().getText()));
        modelBlok6.setB6r21c((getBlok56B().getB6R21c().getText()));
        modelBlok6.setB6r22a(new OpsiB6r22a(getBlok56B().getB6R22a().getText()));
        modelBlok6.setB6r22b(getBlok56B().getB6R22b().getText());
        
        modelBlok6.setB6R22Blainnya(getBlok56B().getB6R22bLainnya().getText());
        
       
        return modelBlok6;
        
    }
    
    
    
    public B7KepalaArt getModelB7(){
        
        //modelBlok7.setKKSArt(getkksart);
       // modelBlok7.setB4Art(null);
        modelBlok7.setB7r1(getBlok789().getB7R1().getText());
        modelBlok7.setB7r2(Int.convertForward(getBlok789().getB7R2().getText()));
        modelBlok7.setB7r3(new OpsiB7r3(getBlok789().getB7R3().getText()));
        modelBlok7.setB7r4(new OpsiB7r4(getBlok789().getB7R4().getText()));
        modelBlok7.setB7r5(Int.convertForward(getBlok789().getB7R5().getText()));
        
        return modelBlok7;
    
    }
    public B8Keteranganperumahandanaset getModelB8(){
        
        modelBlok8.setKks(getKKS());
        modelBlok8.setB8r1(new OpsiB8r1(getBlok789().getB8R1().getText()));
        modelBlok8.setB8r2(new OpsiB8r2(getBlok789().getB8R2().getText()));
        modelBlok8.setB8r3(new OpsiB8r3(getBlok789().getB8R3().getText()));
  
        modelBlok8.setB8r4(Int.convertForward(getBlok789().getB8R4().getText()));
        modelBlok8.setB8r5a(new OpsiB8r5a(getBlok789().getB8R5a().getText()));
        modelBlok8.setB8r5b(new OpsiB8r5b(getBlok789().getB8R5b().getText()));
        modelBlok8.setB8r6(new OpsiB8r6(getBlok789().getB8R6().getText()));
        modelBlok8.setB8r7a(new OpsiB8r7a(getBlok789().getB8R7a().getText()));
        modelBlok8.setB8r7b(new OpsiB8r7b(getBlok789().getB8R7b().getText()));
        modelBlok8.setB8r8(new OpsiB8r8(getBlok789().getB8R8().getText()));
        modelBlok8.setB8r9(new OpsiB8r9(getBlok789().getB8R9().getText()));
        modelBlok8.setB8r10a(getBlok789().getB8R10a().getText());
        modelBlok8.setB8r10b(getBlok789().getB8R10b().getText());
        modelBlok8.setB8r10c(getBlok789().getB8R10c().getText());
        modelBlok8.setB8r10d(getBlok789().getB8R10d().getText());
        modelBlok8.setB8r10e(getBlok789().getB8R10e().getText());
        modelBlok8.setB8r10f(getBlok789().getB8R10f().getText());
        modelBlok8.setB8r10g(getBlok789().getB8R10g().getText());
        modelBlok8.setB8r10h(getBlok789().getB8R10h().getText());
        modelBlok8.setB8r10i(getBlok789().getB8R10i().getText());
        modelBlok8.setB8r10j(getBlok789().getB8R10j().getText());
        return modelBlok8;
    
    }
  
    /**
     * @return the blok1
     */
    public Blok123 getBlok1() {
        return blok1;
    }

    /**
     * @param blok1 the blok1 to set
     */
    public void setBlok1(Blok123 blok1) {
        this.blok1 = blok1;
    }

    /**
     * @return the blok56
     */
    public Blok56 getBlok56() {
        return blok56;
    }

    /**
     * @param blok56 the blok56 to set
     */
    public void setBlok56(Blok56 blok56) {
        this.blok56 = blok56;
    }

    
  

    /**
     * @return the blok4
     */
    public Blok4 getBlok4() {
        return blok4;
    }

    /**
     * @param blok4 the blok4 to set
     */
    public void setBlok4(Blok4 blok4) {
        this.blok4 = blok4;
    }

    /**
     * @param b5List the b5List to set
     */
    public void setB5List(ArrayList<B5Keteranganumumtenagakerjainformal> b5List) {
        this.b5List = b5List;
    }

    /**
     * @param b6List the b6List to set
     */
    public void setB6List(ArrayList<B6Keteranganumumpekerjaaninformalutama> b6List) {
        this.b6List = b6List;
    }

    /**
     * @param b7List the b7List to set
     */
    public void setB7List(ArrayList<B7KepalaArt> b7List) {
        this.b7List = b7List;
    }

    /**
     * @return the blok56B
     */
    public Blok56B getBlok56B() {
        return blok56B;
    }

    /**
     * @param blok56B the blok56B to set
     */
    public void setBlok56B(Blok56B blok56B) {
        this.blok56B = blok56B;
    }

    /**
     * @return the blok789
     */
    public Blok789 getBlok789() {
        return blok789;
    }

    /**
     * @param blok789 the blok789 to set
     */
    public void setBlok789(Blok789 blok789) {
        this.blok789 = blok789;
    }

    /**
     * @return the blok4B
     */
    public Blok4B getBlok4B() {
        return blok4B;
    }

    /**
     * @param blok4B the blok4B to set
     */
    public void setBlok4B(Blok4B blok4B) {
        this.blok4B = blok4B;
    }

 
   
    
}
